﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;
public partial class Bidder_TraSelectSuperviseNext : System.Web.UI.Page, HZ.MBSM.BLL.TraDes
{
    public string _strProjectId;
    string UserCode, _strAccountId,_sort="99";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (HZ.MBSM.BLL.Login.CheckAssert(this.UseAccountType))
        {
            HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];

            if (_Account != null)
            {
                _strProjectId = SysFun.IsSQL(Request.QueryString["ProjectId"].ToString());
                UserCode = _Account.UserCode;
                _strAccountId = _Account.AccountId.ToString();
                _sort = _Account.Sort;
                if ((_Account.Type == "2") && (_Account.Sort == "0"))
                {
                    showGridView();
                }
                else
                {
                    //string strSwl = " select count(*) as cnn from SupplyPlan_Goods where ProjectId=" + _strProjectId + " And IsUse=1 and PS_ChangeStatus ='1' And AccountId_PS=" + _strAccountId;
                    //Db dd = new Db();
                    //DataTable dt = dd.DataTable(strSwl);
                    //if (dt.Rows[0].ItemArray[0].ToString() == "0")
                    //{
                    //    dt.Clear();
                    //    dd.Close();
                    //    Response.Write("<script>alert('您不是主配送商，不能添加分配送企业！');</script>");
                    //    return;
                    //}
                    //else
                    //{
                        //dt.Clear();
                        //dd.Close();
                        showGridView();
                    //}

                }
            }   
            }
    
    }
    public void showGridView()
    {
        string priceTitle = "挂网价";
        string fieldName = "";
        string field = "";
        switch (_strProjectId)
        {
            case "8":
                fieldName = "最高零售价";
                field = " ,convert( numeric(20,2), RetailPrice) as " + fieldName;
                break;
            case "9":
                priceTitle = "最高零售价";
                break;
            case "10":
                priceTitle = "最高限价";
                fieldName = "最高零售价";
                field = " ,convert( numeric(20,2), RetailPrice) as " + fieldName;
                break;
            case "11":
                break;
            case "12":
                priceTitle = "最高零售价";
                break;

        }
        int i = 0;
        string strConditions = fctConditions();
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = "SupplyPlan_Goods";      //要查询的表明
        dbPage.Key = "SupplyGoodsId";     //表的主键    
        dbPage.Where = strConditions;     //查询条件    
        dbPage.SelectField = "SupplyGoodsId,GoodsId,ProductCode,ProductName,MedicineModel" + field + ",Outlookc,SupplyPlan_Goods.ProjectId,Factor,AccountId_SC,CompanyName_SC,AccountId_TB,CompanyName_TB,CompanyName_PS,Accountid_PS,Convert(numeric(20,2),BidPrice) As BidPrice,Case GoodsState When '0' Then '竞价限价' WHEN '1' Then '备案采购(中标价为企业自主报价)' WHEN '2' then '不竞不议' END AS GoodsState,UserCode_SC,UserCode_TB,UserCode_PS,GoodsName,IsNull(Unit,'')+'/'+IsNull(PackUnit,'') As Pack1,QualityLevels As QualityLevels1,CASE QualityLevels " + ConfigurationManager.AppSettings["QualityLevels"].ToString() + " END AS QualityLevels,PS_ChangeStatus";//要显示的字段
        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);          //要显示第几页   
        dbPage.PageSize = 30;                                                    //没有显示记录条数   
        dbPage.OrderBy = "ProductCode,ProductName,MedicineModel,Outlookc,SupplyGoodsId";//排序字段
        System.Text.StringBuilder strHtml = new System.Text.StringBuilder();
        strHtml.Append("<table width='100%' border='0.5' align='left' cellpadding='2' cellspacing='1' class='table_table' id='Mytable'>");
        strHtml.Append("<tr>");
        strHtml.Append("<td    width='3%'>药品流水号</td>");
        strHtml.Append("<td   width='6%'style='display:none'>品目号</td>");
        strHtml.Append("<td   width='8%'>通用名</td>");
        strHtml.Append("<td    width='5%'>商品名</td>");
        strHtml.Append("<td    width='5%'>剂型</td>");
        strHtml.Append("<td    width='3%'>规格</td>");
        strHtml.Append("<td    width='5%'>转换系数</td>");
        strHtml.Append("<td   width='3%'>包装规格</td>");
        strHtml.Append("<td   width='6%'>质量层次</td>");
        strHtml.Append("<td   width='6%'>" + priceTitle + "</td>");

        if (field != "")
        {
            strHtml.Append("<td   width='6%'>" + fieldName + "</td>");
        }
        
        strHtml.Append("<td    width='6%'>投标人</td>");
        strHtml.Append("<td    width='5%'>投标人注册号</td>");
        strHtml.Append("<td   width='9%'>生产企业</td>");
        strHtml.Append("<td    width='5%'>生产企业注册号</td>");
        strHtml.Append("<td    width='5%'>主要配送企业</td>");

        //strHtml.Append("<td    width='5%'>采购目录状态</td>");

        strHtml.Append("<td    width='5%'>选择分配送企业</td>");
        strHtml.Append("</tr>");
        System.Data.IDataReader dr = dbPage.ExecuteReader();

        while (dr.Read())
        {
            if (i == 0)
            {
                strHtml.Append("<tr class='table_td'>");
                i++;
            }
            else
            {
                strHtml.Append("<tr class='table_td2'>");
                i--;
            }

            strHtml.Append("<td width='3%'><input name='IdHao' type='hidden' value='" + dr["SupplyGoodsId"].ToString() + "'>" + dr["GoodsId"].ToString() + "</td>");
            strHtml.Append("<td width='6%' style='display:none'>" + dr["ProductCode"].ToString() + "</td>");
            strHtml.Append("<td width='8%'>" + dr["ProductName"].ToString() + "</td>");
            strHtml.Append("<td width='5%'>" + dr["GoodsName"].ToString() + "</td>");
            strHtml.Append("<td width='5%'>" + dr["Medicinemodel"].ToString() + "</td>");
            strHtml.Append("<td width='3%'>" + dr["Outlookc"].ToString() + "</td>");
            //strHtml.Append("<td nowrap><a href='../Bidder/GoodDetail.aspx?Goodsid=" + dr["GoodsId"].ToString() + "'>商品详细</a></td>");
            strHtml.Append("<td width='5%'>" + dr["Factor"].ToString() + "</td>");
            strHtml.Append("<td width='3%'>" + dr["Pack1"].ToString() + "</td>");
            strHtml.Append("<td width='6%'>" + dr["QualityLevels"].ToString() + "</td>");
            string _strGoodsState = dr["GoodsState"].ToString();
            strHtml.Append("<td width='6%'>" + dr["BidPrice"].ToString() + "</td>");

            if (field != "")
            {
                strHtml.Append("<td   width='6%'>" + dr[fieldName].ToString() + "</td>");
            }
            //switch (_strGoodsState)
            //{
            //    case "竞价限价":
            //        strHtml.Append("<td width='6%'><input type='hidden' name='GoodsState" + dr["SupplyGoodsId"].ToString() + "' value='竞价限价' /><input type='hidden' name='BidPrice" + dr["SupplyGoodsId"].ToString() + "' value='" + dr["BidPrice"].ToString() + "' />" + dr["BidPrice"].ToString() + "</td>");
            //        break;
            //    case "备案采购(中标价为企业自主报价)":
            //        strHtml.Append("<td width='6%'><input type='hidden' name='GoodsState" + dr["SupplyGoodsId"].ToString() + "' value='备案采购' /><input type='hidden' name='BidPrice" + dr["SupplyGoodsId"].ToString() + "' value='" + dr["BidPrice"].ToString() + "' /></td>");
            //        break;
            //    case "不竞不议":
            //        strHtml.Append("<td width='6%'><input type='hidden' name='GoodsState" + dr["SupplyGoodsId"].ToString() + "' value='不竞不议' /><input type='hidden' name='BidPrice" + dr["SupplyGoodsId"].ToString() + "' value='" + dr["BidPrice"].ToString() + "' />" + dr["BidPrice"].ToString() + "</td>");
            //        break;

            //}
            strHtml.Append("<td width='6%'>" + dr["CompanyName_TB"].ToString() + "</td>");
            strHtml.Append("<td width='5%'>" + dr["UserCode_TB"].ToString() + "</td>");
            strHtml.Append("<td width='6%'><input name='txtCompanyName_PS" + dr["SupplyGoodsId"].ToString() + "' type='hidden' value='" + SysFun.ToTrim(dr["CompanyName_PS"].ToString()) + "'>" + dr["CompanyName_SC"].ToString() + "</td>");
            strHtml.Append("<td width='5%'><input name='txtAccountId_PS" + dr["SupplyGoodsId"].ToString() + "' type='hidden' value='" + SysFun.ToInt(dr["AccountId_PS"].ToString()) + "'>" + dr["UserCode_SC"].ToString() + "</td>");

            strHtml.Append("<td width='6%'><input type='hidden' name='AccountId_PS" + dr["SupplyGoodsId"].ToString() + "' value='" + dr["Accountid_PS"].ToString() + "' /><a href='../agency/company_xq.aspx?&Accountid_PS=" + dr["AccountId_PS"].ToString() + "' target='_blank'>" + dr["CompanyName_PS"].ToString() + "</a> </td>");
            //strHtml.Append("<td width='5%'>" + dr["GoodsState"].ToString() + "</td>");
            if (((dr["AccountId_TB"].ToString() == _strAccountId) || (dr["AccountId_SC"].ToString() == _strAccountId) || (dr["AccountId_PS"].ToString() == _strAccountId)) && (dr["PS_ChangeStatus"].ToString().Trim() != ""))
            {
                strHtml.Append("<td width='5%' align='center'  Style=\"color:Red;cursor:hand\"><a href='TraSelectSuperviseNextArea.aspx?SupplyGoodsId=" + dr["SupplyGoodsId"].ToString() + "&projectid=" + _strProjectId + "'>维护分配送企业</a></td>");
            }
            else
            {
                strHtml.Append("<td width='5%' align='center' >&nbsp;</td>");
            }
            strHtml.Append("</tr>");
        }
        strHtml.Append("</table>");
        Label1.Text = strHtml.ToString();


        dr.Close();
        dr.Dispose();
        dbPage.Db.Close();
        db.Close();

        this.DbPageFlip1.DbPage = dbPage;//将数据传给控键

        this.DbPageFlip2.DbPage = dbPage;


    }

    public string fctConditions()
    {
        string strtemp, GoodsState,UserCode_SC, CompanyName_SC, _GoodsId, ProudctName, Outlookc, ProductCode, GoodsName;

        if (_sort == "0")
        {
            //药品查询范围
            //strtemp = " ProjectId=" + _strProjectId + " And IsUse=1 And AccountId_PS=" + _strAccountId + " And AccountId_PS=AccountId_SC AND";
            strtemp = " ProjectId=" + _strProjectId + " And IsUse=1 And AccountId_PS=" + _strAccountId + " And";
        }
        else
        {
            //药品查询范围
            strtemp = " ProjectId=" + _strProjectId + " And IsUse=1 And AccountId_PS=" + _strAccountId + " AND";
        }

        //采购目录状态

        GoodsState = SysFun.ToTrim(DLGoods.SelectedValue);
        switch (GoodsState)
        {
            case "全部":
                break;
            case "原中标商品":
                strtemp += " GoodsState='0' And";
                break;
            case "备案采购商品":
                strtemp += " GoodsState='1' And";
                break;
            case "不限价不竞价商品":
                strtemp += " GoodsState='2' And";
                break;

        }

        //通用名或拼音码

        ProudctName = this.txtProudctName.Text.ToString();
        if (ProudctName != "")
        {
            strtemp += " (ProductName like '%" + ProudctName + "%' or Product_SpellingCode like '%" + ProudctName + "%') and";
        }

        //规格
        Outlookc = this.txtOutLookc.Text.ToString();
        if (Outlookc != "")
        {
            strtemp += " outlookc like '%" + Outlookc + "%' and";
        }

        //流水号

        _GoodsId = SysFun.ToTrim(this.txtGoodsId.Text);
        if (_GoodsId != "")
        {
            strtemp += " GoodsId = '" + _GoodsId + "' and";
        }

        //生产企业名称
        CompanyName_SC = this.txtCompanyName_SC.Text.ToString();
        if (CompanyName_SC != "")
        {
            strtemp += " CompanyName_SC like '%" + CompanyName_SC + "%' and";
        }

        //生产企业编码
        UserCode_SC = this.txtUserCode_SC.Text.ToString();
        if (UserCode_SC != "")
        {
            strtemp += " UserCode_SC like '%" + UserCode_SC + "%' and";
        }

        //品目号

        ProductCode = this.txtProductCode.Text.ToString();
        if (ProductCode != "")
        {
            strtemp = " ProductCode like '%" + ProductCode + "%' and";
        }

        //商品名

        GoodsName = this.txtGoodsName.Text.ToString();
        if (GoodsName != "")
        {
            strtemp += " GoodsName like '%" + GoodsName + "%' and";
        }


        if (strtemp != "")
        {
            strtemp += "  " + strtemp.Substring(0, strtemp.Length - 3);
        }
        return strtemp;

    }
    protected void Button5_Click(object sender, EventArgs e)//查询
    {

    }
    #region TraDes 成员

    public string Name
    {
        get { return "维护配送企业"; }
    }

    public string Describe
    {
        get { return ""; }
    }

    public string ParentName
    {
        get { return "维护配送企业"; }
    }

    public System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> UseAccountType
    {
        get
        {
            System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
            _AccountType.Add(HZ.MBSM.DAL.AccountType.enumCompany);
            return _AccountType;
        }
    }

    #endregion

}
